// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import VueRouter from 'vue-router'
import Routers from './router';
import store from '../lib/store';
import App from './App';
import iView from 'iview';
import '../node_modules/iview/dist/styles/iview.css'


Vue.config.productionTip = true;

Vue.use(iView);
Vue.use(VueRouter);


const RouterConfig = {
    mode: 'history',
    routes: Routers
};

const router = new VueRouter(RouterConfig);

router.beforeEach((to, from, next) => {
    window.document.title = to.meta.title;
    next();
});

router.afterEach((to, from, next) => {
    window.scrollTo(0, 0);
});
/*
const key = 'user';

const store = new Vuex.Store({
    //定义状态
    state() {
        return {
            user: null
        }
    },
    getters: {
        getStorage: function (state) {
            if(!state.user) {
                //user:{token: value, key1: value1, key2: value2}
                state.user = JSON.parse(localStorage.getItem(key));
            }
            return state.user;
        }
    },
    mutations: {
        $_setStorage(state, value) {
            state.user = value;
            localStorage.setItem(key, JSON.stringify(value));
        },
        $_removeStorage(state) {
            state.user = null;
            localStorage.removeItem(key);
        }

    },
    actions: {

    }
});
*/

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router: router,
    store,
    components: {App},
    template: '<App/>'
})
